package com.rrd.hive.udf;

import com.rrd.hive.util.StringPadUtil;
import com.weicai.caesar.Caesar;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;

import java.io.UnsupportedEncodingException;

public class XMRDCreditReportUDF extends UDF {
    public static final String FLAG ="|";
    public Text evaluate(String... arr) throws UnsupportedEncodingException {
        Text text = new Text("");
        if(arr ==null || arr.length<=0){
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (String s:arr){
            if(s == null){
                s="";
            }
            if(Caesar.isEncrypted(s)){
                sb.append(Caesar.decrypt(s)).append(FLAG);
            }else{
                sb.append(s).append(FLAG);
            }


        }
        text.set(sb.substring(0,sb.length()-1));
        return text;

    }

    public static void main(String[] args) throws UnsupportedEncodingException {
        XMRDCreditReportUDF xmrd = new XMRDCreditReportUDF();
        System.out.println(xmrd.evaluate("aa","ss","ff","sdf"));;
    }

}
